<?php
class Fraud extends CI_Model
{
	public $tbl_name = 'user';
	public $col_userid = 'userid';
	public $col_ip = 'ip';
	public $col_username = 'username';
	public $col_email = 'email';


	public $tbl_fraud = 'fraud';
	public $col_fraudId = 'fraudId';
	public $col_isEnable = 'isEnable';

	public function __contruct()
	{
		parent::__construct();	
	}


	public function isEnable($fraudId){

		$this->db->where($this->col_fraudId, $fraudId);
		$this->db->order_by($this->col_fraudId, "asc");
		$this->db->limit(1);

		$this->db->from($this->tbl_fraud);

		return $this->db->get()->row()->isEnable;	
	}


	public function checkIP(){	

		$this->db->where($this->col_ip, $_SERVER['REMOTE_ADDR']);
		$this->db->order_by($this->col_userid, "desc");
		$this->db->limit(1);

		$this->db->from($this->tbl_name);

		if ($this->db->count_all_results() > 0) {
			return false;
		}
		return true;
	}// end checkIP

	public function checkUsername(){	

		$this->db->where($this->col_username, $this->input->post('username'));
		$this->db->order_by($this->col_userid, "desc");
		$this->db->limit(1);

		$this->db->from($this->tbl_name);

		if ($this->db->count_all_results() > 0) {
			return false;
		}
		return true;
	}// end checkUsername

	public function checkEmail(){	

		$this->db->where($this->col_email, $this->input->post('email'));
		$this->db->order_by($this->col_userid, "desc");
		$this->db->limit(1);

		$this->db->from($this->tbl_name);

		if ($this->db->count_all_results() > 0) {
			return false;
		}
		return true;
	}// end checkEmail


	public function getFraudMessage($fraudId){
		
		$query = $this->db->get_where($this->tbl_fraud, array($this->col_fraudId => $fraudId), 1, 0);

		return $query->row()->message;
	}// end IsAuthenticated	
}
?>